﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Logic.Personal;
using Job.Logic.Common;
using Job.Entity;
using System.Collections.Generic;

namespace Job.Web.userControls.Personal
{
    public partial class AccountInfo : System.Web.UI.UserControl
    {
        private int personAccountId
        {
            get
            {
                //后台管理员能通过后台为企业增加职位，所以在此处需要兼职企业ID从url或从Session中获取
                MySession session = new MySession();
                SessionPersonal sPerson = session.GetPersonalFromSession();
                if (null == sPerson)
                    return 0;
                else
                    return sPerson.PersonAccountid;
            }
        }

        PersonalLogic pl = new PersonalLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.LoadData();
                this.LoadInformation();
            }
        }

        private void LoadInformation()
        {
            JobPersonAccount account = pl.GetAccountByAccountid(personAccountId);
            if ( account == null ) return;

            lbUserName.Text = account.UserName;
            lbCreateDate.Text = account.CreateDate.ToString("yyyy-MM-dd");
            lbLoginDate.Text = account.LastLoginDate.Value.ToString("yyyy-MM-dd");
            lbLoginNum.Text = account.LoginNum.ToString();

            ApplyJobLogic ajl = new ApplyJobLogic();
            int count = ajl.CountFavoritesByPerson(personAccountId);
            lbFavoriteNum.Text = count.ToString();

            count = ajl.CountSendByPerson(personAccountId);
            lbSendNum.Text = count.ToString();      
        }


        private void LoadData()
        {

            IList<ResumeList> list = pl.GetResumeList(personAccountId);
            dvResume.DataSource = list;
            dvResume.DataBind();
        }

        protected void dvResume_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbApplyStyle = (Label)e.Row.FindControl("lbApplyStyle");
                if (null != lbApplyStyle)
                {
                    Label lbApplyName = (Label)e.Row.FindControl("lblApplyName");
                    if (null != lbApplyName) lbApplyName.Text = MemoryDictionary.GetCommonDictName(lbApplyStyle.Text);
                }

                Label lblID = (Label)e.Row.FindControl("lblid");
                HyperLink hlModify = (HyperLink)e.Row.FindControl("linkModify");
                if ( hlModify != null )
                {
                    string url = WebCommon.GetApplicationPath(Request)
                        + "Person/PersonalResume.aspx?subjectid=1&categoryid=1&resumeid=" + lblID.Text;
                    hlModify.NavigateUrl = url;
                }

                HyperLink hlResume = (HyperLink)e.Row.FindControl("linkResume");
                if (hlResume != null)
                {
                    string url = WebCommon.GetApplicationPath(Request)
                        + "Common/ResumeBrowse.aspx?categoryid=1&resumeid=" + lblID.Text;
                    hlResume.NavigateUrl = url;
                }
            }
        }

        protected void dvResume_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName.ToLower() == "refresh")
            {
                pl.RefreshResume(id);
                Response.Redirect(this.Request.RawUrl);
            }
        }

        //protected void btnCreateResume_Click(object sender, EventArgs e)
        //{
            
            
        //    Response.Redirect(url);
        //}


    }
}